package com.seafwg.eduservice.controller;


import com.seafwg.commonutils.R;
import com.seafwg.eduservice.entity.subject.OneSubject;
import com.seafwg.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author seafwg
 * @since 2021-01-18
 */
@Api(description = "课程分类管理列表")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类
    //获取上传文件，把文件内容读取出来
    @ApiOperation(value = "上传课程信息")
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile file) {
        /**
         * saveSubject:service层方法，但是service层要点用监听器的方法，监听器无法注入service,
         * 所以通过参数的形式把service传递给监听器
         */
        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    //课程分类列表（树形）
    @GetMapping("/getAllSubject")
    public R getAllSubject() {
        //list集合泛型是一级分类
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }
}

